<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气监听器案例</title>
    <script src="../js/vue.global.js"></script>
</head>
<body>
    <div id="app">
        <h1>今天温度: {{temp}} ℃, 属于 {{this.degree}} 级别</h1>
        <button @click=increase()>上升温度</button> &nbsp;&nbsp; <button @click=decrease()>下降温度</button>
    </div>

    <script>
        const myApp = {
            data()
            {
                return {
                    temp: 35,
                    degree: "凉爽"    
                }
            },
            methods:
            {
                increase()
                {
                    this.temp ++;
                },

                decrease()
                {
                    this.temp --;
                }
            },
            watch:
            {
                temp(newVal, oldVal)
                {
                    this.degree = (this.degree >= 38) ? "炎热" : "凉爽";
                }
            }
        }

        Vue.createApp(myApp).mount("#app");
    </script>
</body>
</html>